package com.example.bodycontrolmodule.impl


import com.example.datacore.Event
import com.example.datacore.IBCMRepository
import com.example.datacore.IEventRepository
import com.example.sourceslibs.SignalType
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.StateFlow
import javax.inject.Inject
import javax.inject.Qualifier
import javax.inject.Singleton

/**
 * 限定符定义 用来区别同一个接口的不同实现
 * */
@Qualifier
@Retention(AnnotationRetention.BINARY)
annotation class TailGateRepository



interface ITailGateRepository: IEventRepository {
    fun getTailGateState(): StateFlow<Int?>
    suspend fun changeTailGateState(b: Boolean)
    suspend fun changeTailGatePos(progress: Int)
}


class TailGateRepositoryImpl @Inject constructor(
    private val bcmRepository: IBCMRepository
):ITailGateRepository{

    override fun getTailGateState(): StateFlow<Int?> {
        return bcmRepository.getStateFlow<Int?>(SignalType.CAR_TAIL_GATE_POS)
    }

    override suspend fun changeTailGateState(b: Boolean) {
        bcmRepository.changeState(SignalType.CAR_TAIL_GATE_STATE,b)
    }

    override suspend fun changeTailGatePos(progress: Int) {
        bcmRepository.changeState(SignalType.CAR_TAIL_GATE_POS,progress)
    }

    override fun getEventFlow(): SharedFlow<Event?> {
        TODO("Not yet implemented")
    }
}


@Module
@InstallIn(SingletonComponent::class)
abstract class TailGateRepositoryModule{
    @Binds
    @Singleton
    @TailGateRepository
    abstract fun createRepository(impl:TailGateRepositoryImpl):ITailGateRepository

}